import httpInstance from "@/utils/http";
import qs from "qs";

//获取系统的公告+根据id查找
export function getSystemAllAPI(
  current: number,
  pageSize: number,
  query: string
) {
  return httpInstance({
    url: "/system/gets",
    method: "POST",
    data: {
      current,
      pageSize,
      query,
    },
  });
}

//新增系统公告
export function addSystemAPI(
  userId: number,
  title: string,
  content: string
) {
  return httpInstance({
    url: "/system/add",
    method: "POST",
    data: {
      userId,
      title,
      content,
    },
  });
}

// 删除系统公告（支持单个和批量删除）
export function deleteSystemAPI(ids: number | number[]) {
  const Ids = Array.isArray(ids) ? ids : [ids];

  return httpInstance({
    url: "/system/delete",
    method: "DELETE",
    params: {
      ids: Ids,
    },
    paramsSerializer: (params) => {
      return qs.stringify(params, { arrayFormat: "repeat" }); // ids=1&ids=2
    },
  });
}

//修改系统公告
export function updateSystemAPI(
  id: number,
  title:string,
  content:string
) {
  return httpInstance({
    url: "/system/update",
    method: "POST",
    data: {
      id,
      title,
      content,
    },
  });
}
